using UnityEngine;

//待机状态
public class EnemyIdleState : EnemyState
{
    private float timer;        // 计时器

    public EnemyIdleState(EnemyFSM manager, string animationName) : base(manager, animationName) { }

    public override void OnEnter()
    {
        base.OnEnter();
        SetVelocity(0, 0);
        timer = Random.Range(0, parameter.idleTime);
    }

    public override void OnUpdate()
    {
        base.OnUpdate();

        // 如果被击中了，转换到受击状态
        if (parameter.isHurt)
        {
            manager.TransitionState(StateType.Hit);
        }

        // 转换到反应状态
        if (parameter.isChase)
        {
            manager.TransitionState(StateType.React);
        }

        // 如果达到空闲时间上限，则转换到巡逻状态
        if (StateDuration >= timer)
        {
            
            manager.TransitionState(StateType.Patrol);
        }
    }

    public override void OnFixedUpdate()
    {
        base.OnFixedUpdate();
    }

    public override void OnExit()
    {
        base.OnExit();
    }
}
